package effective.generic;

public class UnaryFunctionDemo {

	private static UnaryFunction<Object> IDENTITY_FUNCTION = new UnaryFunction<Object>() {

		@Override
		public Object apply(Object arg) {
			return arg;
		}
	};
	
	@SuppressWarnings("unchecked")
	public static <T> UnaryFunction<T> indentityFunction() {
		return (UnaryFunction<T>) IDENTITY_FUNCTION;
	}
	
	public static void main(String[] args) {
		String[] strings = {"jute", "hemp", "nylon"};
		UnaryFunction<String> sameString = indentityFunction();
		for (String s : strings) {
			System.out.println(sameString.apply(s));
		}
		
		Number[] numbers = {1, 2.0, 3L};
		UnaryFunction<Number> sameNumber = indentityFunction();
		for (Number n : numbers) {
			System.out.println(sameNumber.apply(n));
		}
	}
}
